home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / arts / debug.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-09-10  |  4.3 KB  |  139 lines

  1.     /*
  2.  
  3.     Copyright (C) 2000 Stefan Westerfeld
  4.                        stefan@space.twc.de
  5.  
  6.     This library is free software; you can redistribute it and/or
  7.     modify it under the terms of the GNU Library General Public
  8.     License as published by the Free Software Foundation; either
  9.     version 2 of the License, or (at your option) any later version.
  10.   
  11.     This library is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.     Library General Public License for more details.
  15.    
  16.     You should have received a copy of the GNU Library General Public License
  17.     along with this library; see the file COPYING.LIB.  If not, write to
  18.     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19.     Boston, MA 02111-1307, USA.
  20.  
  21.  
  22.     Some inspiration taken from glib.
  23.     Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
  24.     Modified by the GLib Team and others 1997-1999.
  25.  
  26.     */
  27.  
  28. #ifndef _ARTSDEBUG_H_
  29. #define _ARTSDEBUG_H_
  30.  
  31. #include "arts_export.h"
  32.  
  33. /*
  34.  * BC - Status (2002-03-08): Debug.
  35.  *
  36.  * Collection class, no instance, no members. Thus binary compatible (will
  37.  * be kept).
  38.  */
  39.  
  40. #define arts_fatal        ::Arts::Debug::fatal
  41. #define arts_warning    ::Arts::Debug::warning
  42. #define arts_info        ::Arts::Debug::info
  43. #define arts_debug        ::Arts::Debug::debug
  44.  
  45. /* source compatibility with older sources */
  46. #define artsdebug        ::Arts::Debug::debug
  47. #define setartsdebug(x)    arts_warning("setartsdebug is obsolete")
  48.  
  49. #ifdef __GNUC__
  50.  
  51. #define arts_return_if_fail(expr)                                        \
  52.      do {                                                                \
  53.        if (!(expr))                                                       \
  54.        {                                                                \
  55.          arts_warning ("file %s: line %d (%s): assertion failed: (%s)", \
  56.           __FILE__, __LINE__, __PRETTY_FUNCTION__, #expr);                \
  57.          return;                                                        \
  58.        }                                                                \
  59.      } while(0)
  60.  
  61. #define arts_return_val_if_fail(expr,val)                                \
  62.      do {                                                                \
  63.        if (!(expr))                                                       \
  64.        {                                                                \
  65.          arts_warning ("file %s: line %d (%s): assertion failed: (%s)", \
  66.             __FILE__, __LINE__, __PRETTY_FUNCTION__, #expr);            \
  67.          return (val);                                                    \
  68.        }                                                                \
  69.      } while(0)
  70.  
  71. #define arts_assert(expr)                                                \
  72.      do {                                                                \
  73.        if (!(expr))                                                       \
  74.          arts_fatal ("file %s: line %d (%s): assertion failed: (%s)",      \
  75.             __FILE__, __LINE__, __PRETTY_FUNCTION__, #expr);            \
  76.      } while(0)
  77.  
  78. #else
  79.  
  80. #define arts_return_if_fail(expr)                                        \
  81.      do {                                                                \
  82.        if (!(expr))                                                       \
  83.        {                                                                \
  84.          arts_warning ("file %s: line %d: assertion failed: (%s)",      \
  85.             __FILE__, __LINE__, #expr);                                    \
  86.          return;                                                        \
  87.        }        \
  88.      } while(0)
  89.  
  90. #define arts_return_val_if_fail(expr,val)                                \
  91.      do {                                                                \
  92.        if (!(expr))                                                       \
  93.        {                                                                \
  94.          arts_warning ("file %s: line %d: assertion failed: (%s)",          \
  95.             __FILE__, __LINE__, #expr);                                    \
  96.          return (val);                                                    \
  97.        }                                                                \
  98.      } while(0)
  99.  
  100. #define arts_assert(expr)                                                \
  101.      do {                                                                \
  102.        if (!(expr))                                                       \
  103.          arts_fatal ("file %s: line %d: assertion failed: (%s)",          \
  104.             __FILE__, __LINE__, #expr);                                    \
  105.      } while(0)
  106.  
  107. #endif
  108.  
  109. ARTS_EXPORT char* arts_strdup_printf (const char *format, ...);
  110.  
  111. namespace Arts {
  112.     class ARTS_EXPORT Debug {
  113.     public:
  114.         enum Level { lFatal = 3, lWarning = 2, lInfo = 1, lDebug = 0 };
  115.  
  116.         /**
  117.          * Initializes at which is the minimum level to react to. If you
  118.          * call this, call this before creating the Arts::Dispatcher object.
  119.          */
  120.         static void init(const char *prefix, Level level);
  121.  
  122.         static void fatal(const char *fmt,...);        // print on stderr & abort
  123.         static void warning(const char *fmt,...);    // print on stderr
  124.         static void info(const char *fmt,...);        // print on stdout
  125.         static void debug(const char *fmt,...);        // print on stdout
  126.  
  127.         /**
  128.           * This method sets the name of an external application to
  129.          * display messages graphically.
  130.           */
  131.         static void messageApp(const char *appName);
  132.  
  133.         static void initMutex();    // called from the dispatcher constructor
  134.         static void freeMutex();    // called from the dispatcher destructor
  135.     };
  136. }
  137.  
  138. #endif
  139.